Get the actual module object for a given objectΒΆ

Get the actual module object for a given object.
from inspect import getmodule
from math import sqrt

print(getmodule(sqrt))

Output:

<module 'math' (built-in)>